package client;

import lovedna.ds.Array2D;
import lovedna.utils.DynamicPool;
import lovedna.IInstanceID;

class CellData implements IInstanceID {
    public static inline var type_animal:Int=0;
    public static inline var type_jump0:Int=1;
    public static inline var type_jump90:Int=2;
    public static inline var type_jump180:Int=3;
    public static inline var type_jump270:Int=4;
    private static var _id=0;
	public var instanceID(default, null):Int;
	private static var _pool:DynamicPool<CellData> = new DynamicPool<CellData>(function () {
        return new CellData();
    });
    public var animal:Animal;
    public var type:Int;

	private function new() {
        instanceID=_id++;
        type=type_animal;
    }
    public static function get() {
        return _pool.get();
    }
    public function dispose() {
        animal=null;
        type=type_animal;
        _pool.set(this);
    }
    public function clear() {
        animal=null;
        type=type_animal;
    }
    public function isAnimalType() {
        return type==type_animal;
    }
    public function existAnimal() {
        return animal!=null;
    }
	public function moveIn(animal:Animal, table:Array2D<CellData>) {
        
    }
	public function moveOutBefore(animal:Animal, table:Array2D<CellData>) {
        if(type==type_jump270){
            animal.forwardX=-1;
            animal.forwardY=0;
            animal.forwardHeight=3;
        }else if(type==type_jump0){
            animal.forwardX=0;
            animal.forwardY=1;
            animal.forwardHeight=3;
        }else if(type==type_jump90){
            animal.forwardX=1;
            animal.forwardY=0;
            animal.forwardHeight=3;
        }else if(type==type_jump180){
            animal.forwardX=0;
            animal.forwardY=-1;
            animal.forwardHeight=3;
        }
    }
	public function moveOutAfter(animal:Animal, table:Array2D<CellData>) {
        if(type==type_jump270){
            animal.forwardX=0;
            animal.forwardY=0;
        }else if(type==type_jump0){
            animal.forwardX=0;
            animal.forwardY=0;
        }else if(type==type_jump90){
            animal.forwardX=0;
            animal.forwardY=0;
        }else if(type==type_jump180){
            animal.forwardX=0;
            animal.forwardY=0;
        }
    }
}
